package com.bykj.taketurns.findfragment.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bykj.taketurns.R;
import com.bykj.taketurns.activity.PlayVideoActivity;
import com.bykj.taketurns.findfragment.bean.ThreeVideoBean;
import com.bykj.taketurns.homefragment.activity.StageVideoActivity;

import java.util.List;


public class ThreeVideoAdapter extends RecyclerView.Adapter<ThreeVideoAdapter.ViewHolder> {

    private Context context;
    private List<ThreeVideoBean.StoryvideoBean> list;

    public ThreeVideoAdapter(Context context, List<ThreeVideoBean.StoryvideoBean> storyvideo) {
        this.context = context;
        this.list = storyvideo;
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.script_recyclerview_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {

        holder.tv_stage_script.setText(list.get(position).getPname());
        holder.tv_title_script.setText(list.get(position).getSpname());
        holder.tv_sum_script.setText(list.get(position).getCount() + "");
        holder.rv_data_script.setLayoutManager(new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.HORIZONTAL));

        ThreeVideoItemAdapter threeVideoItemAdapter = new ThreeVideoItemAdapter(context,list.get(position).getStoryVideoSet());
        holder.rv_data_script.setAdapter(threeVideoItemAdapter);
        //条目点击事件
        threeVideoItemAdapter.setOnItemClickListener(new ThreeVideoItemAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int positions) {
                //跳转视频播放页面
                Intent intent=new Intent(context, PlayVideoActivity.class);
                context.startActivity(intent);
            }
        });

        holder.iv_more_script.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, StageVideoActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("tid" , list.get(position).getStoryVideoSet().get(position).getTid());
                bundle.putString("pid" , list.get(position).getStoryVideoSet().get(position).getPid());
                bundle.putString("title" , list.get(position).getSpname());
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        TextView tv_stage_script;
        TextView tv_title_script;
        TextView tv_sum_script;
        ImageView iv_more_script;
        RecyclerView rv_data_script;

        ViewHolder(View view) {
            super(view);

            tv_stage_script = view.findViewById(R.id.tv_stage_script);
            tv_title_script = view.findViewById(R.id.tv_title_script);
            tv_sum_script = view.findViewById(R.id.tv_sum_script);
            iv_more_script = view.findViewById(R.id.iv_more_script);
            rv_data_script = view.findViewById(R.id.rv_data_script);

        }
    }
}
